package com.api.wall.getcompanyfeedevents;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IWallApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.CollectionResultApi;
import com.zyncro.api.model.EventApi;
import com.zyncro.api.model.EventApiType;
import com.zyncro.api.model.EventViewApiType;

@ContextConfiguration(locations = { "classpath:/wall/wall-static.xml" })
public class GetCompanyFeedEvents extends AbstractApiTest {

	@Value("#{org_staticfeeds[toGetCompanyFeed].appId}")
	private String userUrn;

	@Value("#{org_staticfeeds[toGetCompanyFeed].password}")
	private String userPassword;

	@Value("#{org_staticfeeds.totalCompanyFeeds}")
	private int totalCompanyFeed;

	@Value("#{org_staticfeeds.totalCompanyComments}")
	private int totalCompanyComments;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testGetCompanyFeed() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;
		List<EventApiType> eventTypes = null;
		boolean includeHtml = false;
		EventViewApiType viewType = null;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getCompanyFeedEvents(date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalCompanyFeed, "Total Company feeds");
	}

	@Test
	public void testGetCompanyFeedIncludingHtml() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;
		List<EventApiType> eventTypes = null;

		boolean includeHtml = true;

		EventViewApiType viewType = null;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getCompanyFeedEvents(date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalCompanyFeed, "Total Company feeds");
	}

	@Test
	public void testGetCompanyFeedEventTypes() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;

		List<EventApiType> eventTypes = new ArrayList<EventApiType>();
		eventTypes.add(EventApiType.COMMENT);

		boolean includeHtml = false;
		EventViewApiType viewType = null;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getCompanyFeedEvents(date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalCompanyFeed, "Total Company feeds");
	}

	@Test
	public void testGetCompanyFeedBubbling() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;

		List<EventApiType> eventTypes = null;

		boolean includeHtml = false;
		EventViewApiType viewType = EventViewApiType.BUBBLING;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getCompanyFeedEvents(date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalCompanyFeed, "Total Company feeds");
	}

	@Test
	public void testGetCompanyFeedConversation() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;

		List<EventApiType> eventTypes = null;

		boolean includeHtml = false;
		EventViewApiType viewType = EventViewApiType.CONVERSATION;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getCompanyFeedEvents(date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalCompanyFeed, "Total Company feeds");
	}

	@Test
	public void testGetCompanyFeedTwitter() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;

		List<EventApiType> eventTypes = null;

		boolean includeHtml = false;
		EventViewApiType viewType = EventViewApiType.CONVERSATION;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getCompanyFeedEvents(date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalCompanyFeed + totalCompanyComments, "Total Company feeds");
	}
}
